package acm;

import java.util.Scanner;

public class a14 {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int n=in.nextInt();
        int [][] a =new int [n+1][n+1];
        for (int i=1;i<=n;i++){
            for (int j=1;j<=i;j++){
                a[i][j]=in.nextInt();
            }

        }


        for (int i=n;i>=1;i--){
            for (int j=1;j<=i-1;j++){
                a[i-1][j]+=Math.max(a[i][j],a[i][j+1]);
            }
        }
        System.out.print(a[1][1]);

    }
}
